﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Xml;
public class WeaponManager : Singleton<WeaponManager> 
{
    public Dictionary<string, XmlWeapon> Weapons = new Dictionary<string,XmlWeapon>();

    public void InitFormXml() 
    {
        string xmlPath = Game.ConfigPath + "Weapons.xml";
        string strWeapon = File.ReadAllText(xmlPath);
        XmlDocument xmlDoc = new XmlDocument();
        xmlDoc.LoadXml(strWeapon);
        XmlNode weaponRootNode = xmlDoc.ChildNodes[0];
        for (int i = 0; i < weaponRootNode.ChildNodes.Count;i++ )
        {
            XmlWeapon xmlWeapon = new XmlWeapon(weaponRootNode.ChildNodes[i]);
            string weaponName = weaponRootNode.ChildNodes[i].Attributes["Name"].Value;
            this.Weapons.Add(weaponName,xmlWeapon);
        }
    } 

    
}

public class XmlWeapon 
{
    public string WeaponName;
    public string EffectName; 
    public float AttackSpeed;
    public float AttackRange;
    public float BeforeAttackRoll;
    public XmlWeapon(XmlNode node) 
    {
        this.WeaponName =node.Attributes["Name"].Value;
        this.EffectName = node.Attributes["EffectName"].Value;
        this.AttackSpeed = float.Parse(node.Attributes["AttackSpeed"].Value);
        this.AttackRange = float.Parse(node.Attributes["AttackRange"].Value);
        if (node.Attributes["BeforeAttackRoll"] != null)
        {
            this.BeforeAttackRoll = float.Parse(node.Attributes["BeforeAttackRoll"].Value);
        } 
    }
}